function [x,fval,residual,exitflag,output]=optim_fitsubphase(Param,xdata,ydata,yerr,LB,UB)
options=optimset('MaxIter',500,'TolFun',1e-8,'Display','iter','TolX',1e-8,'MaxFunEvals',2000);
[x,fval,residual,exitflag,output]=lsqcurvefit(@nestedfun,Param,xdata,(ydata./yerr),LB,UB,options);
    function y=nestedfun(Param,xdata)
        
        C=Param(1);
        qc=Param(2);
        bkg=Param(3);
        
        qz=xdata;
        Energy=13.474; %  Incident X-ray Photon energy (keV)
        Attl= 4854.22e4; % Attenuation length in unit of Angstrom for water @ 13.474 keV
        %Attl=900e4;
        mu=1/Attl;
        lambda=0.9201; % in unit of Angstrom
        beta=mu*lambda/4/pi;
      
        t=Transmission(qz,qc,beta,lambda);
        y=bkg+C*t.*fitsubphase(qz,qc,Energy,Attl);
        y=(y./yerr);
    end
end
